import {http} from '../resources'
/**
 * Custom validators for VeeValidate
 * @author danea
 */
export default {

  // Server side validation
  remote: {
    getMessage: (field) => `${field} already exists or it's not valid.`,
    // If you want to return a promise you will have to make sure it always resolves
    // to an object containing a 'valid' property which is a boolean state of the validation.
    validate: (val, args, field) => {
      return new Promise(resolve => {
        setTimeout(() => {
              http.get(args[0] + val).then(response => {
                resolve({
                  valid: !response.data.code
                })
              })
            },500
        )
      })
    }
  },
  unique: {
    getMessage: (field) => `${field} must be unique.`,
    // If you want to return a promise you will have to make sure it always resolves
    // to an object containing a 'valid' property which is a boolean state of the validation.
    validate: (val, args, field) => {
      return false
    }
  }
}
